{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import jqdatasdk\n",
    "from jqdatasdk import get_all_securities\n",
    "import pandas as pd\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "auth success \n"
     ]
    }
   ],
   "source": [
    "with open(\"../data/auth_key.key\") as key:\n",
    "    auth_key = key.read().split(\",\")\n",
    "    jqdatasdk.auth(auth_key[0], auth_key[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_code = jqdatasdk.get_all_securities(['stock'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_code['code']=stock_code.display_name.index.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_code.index=[x for x in range(len(stock_code))]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 取上市日期在2010之前的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "pre_stock=stock_code[stock_code['start_date']<datetime.datetime.strptime('2010-1-1','%Y-%m-%d')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1736, 6)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pre_stock.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取得时间段\n",
    "start_date = datetime.datetime.now() + datetime.timedelta(days=-365)\n",
    "end_date = datetime.datetime.now()\n",
    "start_date=start_date.strftime(\"%Y-%m-%d %H:%M:%S\")\n",
    "end_date=end_date.strftime(\"%Y-%m-%d\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "workTime = ['09:00:00', '15:30:00']\n",
    "dayOfWeek = datetime.datetime.now().weekday()\n",
    "beginWork = datetime.datetime.now().strftime(\"%Y-%m-%d\") + ' ' + workTime[0]\n",
    "endWork = datetime.datetime.now().strftime(\"%Y-%m-%d\") + ' ' + workTime[1]\n",
    "beginWork=datetime.datetime.strptime(beginWork,\"%Y-%m-%d %H:%M:%S\")\n",
    "endWork=datetime.datetime.strptime(endWork,\"%Y-%m-%d %H:%M:%S\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2019, 10, 29, 15, 30)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "endWork"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "security='000001.XSHE'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = jqdatasdk.get_price(security, start_date=beginWork, end_date=endWork,\n",
    "                                           frequency='1m',\n",
    "                                           fields=None,\n",
    "                                           skip_paused=False, fq='pre')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>money</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:31:00</th>\n",
       "      <td>16.69</td>\n",
       "      <td>16.67</td>\n",
       "      <td>16.70</td>\n",
       "      <td>16.67</td>\n",
       "      <td>2352482.0</td>\n",
       "      <td>39246570.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:32:00</th>\n",
       "      <td>16.67</td>\n",
       "      <td>16.66</td>\n",
       "      <td>16.68</td>\n",
       "      <td>16.65</td>\n",
       "      <td>959130.0</td>\n",
       "      <td>15982368.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:33:00</th>\n",
       "      <td>16.66</td>\n",
       "      <td>16.63</td>\n",
       "      <td>16.67</td>\n",
       "      <td>16.62</td>\n",
       "      <td>358242.0</td>\n",
       "      <td>5962861.64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:34:00</th>\n",
       "      <td>16.62</td>\n",
       "      <td>16.60</td>\n",
       "      <td>16.63</td>\n",
       "      <td>16.60</td>\n",
       "      <td>549197.0</td>\n",
       "      <td>9129430.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:35:00</th>\n",
       "      <td>16.60</td>\n",
       "      <td>16.58</td>\n",
       "      <td>16.61</td>\n",
       "      <td>16.56</td>\n",
       "      <td>420517.0</td>\n",
       "      <td>6976555.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:36:00</th>\n",
       "      <td>16.57</td>\n",
       "      <td>16.61</td>\n",
       "      <td>16.62</td>\n",
       "      <td>16.57</td>\n",
       "      <td>321875.0</td>\n",
       "      <td>5341366.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:37:00</th>\n",
       "      <td>16.61</td>\n",
       "      <td>16.62</td>\n",
       "      <td>16.63</td>\n",
       "      <td>16.60</td>\n",
       "      <td>436840.0</td>\n",
       "      <td>7258228.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:38:00</th>\n",
       "      <td>16.62</td>\n",
       "      <td>16.62</td>\n",
       "      <td>16.64</td>\n",
       "      <td>16.61</td>\n",
       "      <td>267894.0</td>\n",
       "      <td>4453106.65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:39:00</th>\n",
       "      <td>16.61</td>\n",
       "      <td>16.60</td>\n",
       "      <td>16.63</td>\n",
       "      <td>16.60</td>\n",
       "      <td>235699.0</td>\n",
       "      <td>3915105.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:40:00</th>\n",
       "      <td>16.60</td>\n",
       "      <td>16.61</td>\n",
       "      <td>16.61</td>\n",
       "      <td>16.59</td>\n",
       "      <td>235822.0</td>\n",
       "      <td>3914556.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:41:00</th>\n",
       "      <td>16.62</td>\n",
       "      <td>16.61</td>\n",
       "      <td>16.64</td>\n",
       "      <td>16.61</td>\n",
       "      <td>255153.0</td>\n",
       "      <td>4240954.21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:42:00</th>\n",
       "      <td>16.62</td>\n",
       "      <td>16.62</td>\n",
       "      <td>16.62</td>\n",
       "      <td>16.61</td>\n",
       "      <td>199611.0</td>\n",
       "      <td>3317167.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:43:00</th>\n",
       "      <td>16.62</td>\n",
       "      <td>16.62</td>\n",
       "      <td>16.62</td>\n",
       "      <td>16.61</td>\n",
       "      <td>206416.0</td>\n",
       "      <td>3429883.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:44:00</th>\n",
       "      <td>16.62</td>\n",
       "      <td>16.64</td>\n",
       "      <td>16.65</td>\n",
       "      <td>16.62</td>\n",
       "      <td>221261.0</td>\n",
       "      <td>3680651.08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:45:00</th>\n",
       "      <td>16.64</td>\n",
       "      <td>16.66</td>\n",
       "      <td>16.66</td>\n",
       "      <td>16.64</td>\n",
       "      <td>210697.0</td>\n",
       "      <td>3507788.02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:46:00</th>\n",
       "      <td>16.66</td>\n",
       "      <td>16.66</td>\n",
       "      <td>16.67</td>\n",
       "      <td>16.65</td>\n",
       "      <td>301487.0</td>\n",
       "      <td>5022326.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:47:00</th>\n",
       "      <td>16.66</td>\n",
       "      <td>16.67</td>\n",
       "      <td>16.67</td>\n",
       "      <td>16.65</td>\n",
       "      <td>258200.0</td>\n",
       "      <td>4301558.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:48:00</th>\n",
       "      <td>16.67</td>\n",
       "      <td>16.68</td>\n",
       "      <td>16.68</td>\n",
       "      <td>16.66</td>\n",
       "      <td>304199.0</td>\n",
       "      <td>5071893.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:49:00</th>\n",
       "      <td>16.68</td>\n",
       "      <td>16.71</td>\n",
       "      <td>16.72</td>\n",
       "      <td>16.68</td>\n",
       "      <td>548012.0</td>\n",
       "      <td>9151777.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:50:00</th>\n",
       "      <td>16.71</td>\n",
       "      <td>16.76</td>\n",
       "      <td>16.77</td>\n",
       "      <td>16.71</td>\n",
       "      <td>957394.0</td>\n",
       "      <td>16032557.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:51:00</th>\n",
       "      <td>16.77</td>\n",
       "      <td>16.74</td>\n",
       "      <td>16.77</td>\n",
       "      <td>16.73</td>\n",
       "      <td>930627.0</td>\n",
       "      <td>15592059.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:52:00</th>\n",
       "      <td>16.73</td>\n",
       "      <td>16.72</td>\n",
       "      <td>16.73</td>\n",
       "      <td>16.71</td>\n",
       "      <td>371783.0</td>\n",
       "      <td>6217631.62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:53:00</th>\n",
       "      <td>16.71</td>\n",
       "      <td>16.72</td>\n",
       "      <td>16.73</td>\n",
       "      <td>16.71</td>\n",
       "      <td>449000.0</td>\n",
       "      <td>7509687.08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:54:00</th>\n",
       "      <td>16.73</td>\n",
       "      <td>16.73</td>\n",
       "      <td>16.74</td>\n",
       "      <td>16.72</td>\n",
       "      <td>302468.0</td>\n",
       "      <td>5061081.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:55:00</th>\n",
       "      <td>16.72</td>\n",
       "      <td>16.73</td>\n",
       "      <td>16.74</td>\n",
       "      <td>16.72</td>\n",
       "      <td>283110.0</td>\n",
       "      <td>4737109.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:56:00</th>\n",
       "      <td>16.73</td>\n",
       "      <td>16.71</td>\n",
       "      <td>16.73</td>\n",
       "      <td>16.70</td>\n",
       "      <td>694471.0</td>\n",
       "      <td>11608514.35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:57:00</th>\n",
       "      <td>16.72</td>\n",
       "      <td>16.70</td>\n",
       "      <td>16.72</td>\n",
       "      <td>16.70</td>\n",
       "      <td>418072.0</td>\n",
       "      <td>6983417.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:58:00</th>\n",
       "      <td>16.70</td>\n",
       "      <td>16.71</td>\n",
       "      <td>16.71</td>\n",
       "      <td>16.70</td>\n",
       "      <td>253615.0</td>\n",
       "      <td>4236408.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 09:59:00</th>\n",
       "      <td>16.71</td>\n",
       "      <td>16.70</td>\n",
       "      <td>16.71</td>\n",
       "      <td>16.70</td>\n",
       "      <td>253002.0</td>\n",
       "      <td>4226400.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 10:00:00</th>\n",
       "      <td>16.71</td>\n",
       "      <td>16.68</td>\n",
       "      <td>16.71</td>\n",
       "      <td>16.68</td>\n",
       "      <td>520025.0</td>\n",
       "      <td>8679970.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:31:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>182220.0</td>\n",
       "      <td>3066045.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:32:00</th>\n",
       "      <td>16.83</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.84</td>\n",
       "      <td>16.82</td>\n",
       "      <td>489302.0</td>\n",
       "      <td>8236260.64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:33:00</th>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.84</td>\n",
       "      <td>16.82</td>\n",
       "      <td>288600.0</td>\n",
       "      <td>4857584.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:34:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.84</td>\n",
       "      <td>16.82</td>\n",
       "      <td>252092.0</td>\n",
       "      <td>4242779.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:35:00</th>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>428300.0</td>\n",
       "      <td>7209004.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:36:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.85</td>\n",
       "      <td>16.85</td>\n",
       "      <td>16.82</td>\n",
       "      <td>819100.0</td>\n",
       "      <td>13788395.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:37:00</th>\n",
       "      <td>16.84</td>\n",
       "      <td>16.84</td>\n",
       "      <td>16.85</td>\n",
       "      <td>16.83</td>\n",
       "      <td>255923.0</td>\n",
       "      <td>4310376.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:38:00</th>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.84</td>\n",
       "      <td>16.81</td>\n",
       "      <td>567200.0</td>\n",
       "      <td>9544310.62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:39:00</th>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.84</td>\n",
       "      <td>16.81</td>\n",
       "      <td>717560.0</td>\n",
       "      <td>12070802.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:40:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.81</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.80</td>\n",
       "      <td>235607.0</td>\n",
       "      <td>3960619.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:41:00</th>\n",
       "      <td>16.80</td>\n",
       "      <td>16.80</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.80</td>\n",
       "      <td>340540.0</td>\n",
       "      <td>5723429.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:42:00</th>\n",
       "      <td>16.80</td>\n",
       "      <td>16.81</td>\n",
       "      <td>16.81</td>\n",
       "      <td>16.79</td>\n",
       "      <td>486056.0</td>\n",
       "      <td>8166909.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:43:00</th>\n",
       "      <td>16.80</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.80</td>\n",
       "      <td>474361.0</td>\n",
       "      <td>7976260.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:44:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.81</td>\n",
       "      <td>261949.0</td>\n",
       "      <td>4405748.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:45:00</th>\n",
       "      <td>16.81</td>\n",
       "      <td>16.81</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.81</td>\n",
       "      <td>310400.0</td>\n",
       "      <td>5220694.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:46:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>459929.0</td>\n",
       "      <td>7738115.78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:47:00</th>\n",
       "      <td>16.83</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>359122.0</td>\n",
       "      <td>6043664.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:48:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>367926.0</td>\n",
       "      <td>6190146.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:49:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>320957.0</td>\n",
       "      <td>5400481.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:50:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>385542.0</td>\n",
       "      <td>6487444.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:51:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.82</td>\n",
       "      <td>16.83</td>\n",
       "      <td>16.82</td>\n",
       "      <td>463000.0</td>\n",
       "      <td>7789842.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:52:00</th>\n",
       "      <td>16.82</td>\n",
       "      <td>16.87</td>\n",
       "      <td>16.87</td>\n",
       "      <td>16.82</td>\n",
       "      <td>2959534.0</td>\n",
       "      <td>49858901.68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:53:00</th>\n",
       "      <td>16.87</td>\n",
       "      <td>16.90</td>\n",
       "      <td>16.91</td>\n",
       "      <td>16.87</td>\n",
       "      <td>2022700.0</td>\n",
       "      <td>34174144.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:54:00</th>\n",
       "      <td>16.89</td>\n",
       "      <td>16.90</td>\n",
       "      <td>16.90</td>\n",
       "      <td>16.88</td>\n",
       "      <td>927300.0</td>\n",
       "      <td>15667605.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:55:00</th>\n",
       "      <td>16.89</td>\n",
       "      <td>16.89</td>\n",
       "      <td>16.90</td>\n",
       "      <td>16.88</td>\n",
       "      <td>802510.0</td>\n",
       "      <td>13556824.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:56:00</th>\n",
       "      <td>16.88</td>\n",
       "      <td>16.87</td>\n",
       "      <td>16.89</td>\n",
       "      <td>16.87</td>\n",
       "      <td>821190.0</td>\n",
       "      <td>13862545.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:57:00</th>\n",
       "      <td>16.87</td>\n",
       "      <td>16.89</td>\n",
       "      <td>16.90</td>\n",
       "      <td>16.86</td>\n",
       "      <td>542624.0</td>\n",
       "      <td>9159236.64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:58:00</th>\n",
       "      <td>16.89</td>\n",
       "      <td>16.89</td>\n",
       "      <td>16.89</td>\n",
       "      <td>16.89</td>\n",
       "      <td>5900.0</td>\n",
       "      <td>99651.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 14:59:00</th>\n",
       "      <td>16.89</td>\n",
       "      <td>16.89</td>\n",
       "      <td>16.89</td>\n",
       "      <td>16.89</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-10-29 15:00:00</th>\n",
       "      <td>16.89</td>\n",
       "      <td>16.91</td>\n",
       "      <td>16.91</td>\n",
       "      <td>16.89</td>\n",
       "      <td>1513462.0</td>\n",
       "      <td>25592642.42</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>240 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                      open  close   high    low     volume        money\n",
       "2019-10-29 09:31:00  16.69  16.67  16.70  16.67  2352482.0  39246570.48\n",
       "2019-10-29 09:32:00  16.67  16.66  16.68  16.65   959130.0  15982368.97\n",
       "2019-10-29 09:33:00  16.66  16.63  16.67  16.62   358242.0   5962861.64\n",
       "2019-10-29 09:34:00  16.62  16.60  16.63  16.60   549197.0   9129430.29\n",
       "2019-10-29 09:35:00  16.60  16.58  16.61  16.56   420517.0   6976555.18\n",
       "2019-10-29 09:36:00  16.57  16.61  16.62  16.57   321875.0   5341366.55\n",
       "2019-10-29 09:37:00  16.61  16.62  16.63  16.60   436840.0   7258228.19\n",
       "2019-10-29 09:38:00  16.62  16.62  16.64  16.61   267894.0   4453106.65\n",
       "2019-10-29 09:39:00  16.61  16.60  16.63  16.60   235699.0   3915105.18\n",
       "2019-10-29 09:40:00  16.60  16.61  16.61  16.59   235822.0   3914556.27\n",
       "2019-10-29 09:41:00  16.62  16.61  16.64  16.61   255153.0   4240954.21\n",
       "2019-10-29 09:42:00  16.62  16.62  16.62  16.61   199611.0   3317167.71\n",
       "2019-10-29 09:43:00  16.62  16.62  16.62  16.61   206416.0   3429883.76\n",
       "2019-10-29 09:44:00  16.62  16.64  16.65  16.62   221261.0   3680651.08\n",
       "2019-10-29 09:45:00  16.64  16.66  16.66  16.64   210697.0   3507788.02\n",
       "2019-10-29 09:46:00  16.66  16.66  16.67  16.65   301487.0   5022326.11\n",
       "2019-10-29 09:47:00  16.66  16.67  16.67  16.65   258200.0   4301558.00\n",
       "2019-10-29 09:48:00  16.67  16.68  16.68  16.66   304199.0   5071893.77\n",
       "2019-10-29 09:49:00  16.68  16.71  16.72  16.68   548012.0   9151777.44\n",
       "2019-10-29 09:50:00  16.71  16.76  16.77  16.71   957394.0  16032557.50\n",
       "2019-10-29 09:51:00  16.77  16.74  16.77  16.73   930627.0  15592059.95\n",
       "2019-10-29 09:52:00  16.73  16.72  16.73  16.71   371783.0   6217631.62\n",
       "2019-10-29 09:53:00  16.71  16.72  16.73  16.71   449000.0   7509687.08\n",
       "2019-10-29 09:54:00  16.73  16.73  16.74  16.72   302468.0   5061081.96\n",
       "2019-10-29 09:55:00  16.72  16.73  16.74  16.72   283110.0   4737109.43\n",
       "2019-10-29 09:56:00  16.73  16.71  16.73  16.70   694471.0  11608514.35\n",
       "2019-10-29 09:57:00  16.72  16.70  16.72  16.70   418072.0   6983417.37\n",
       "2019-10-29 09:58:00  16.70  16.71  16.71  16.70   253615.0   4236408.50\n",
       "2019-10-29 09:59:00  16.71  16.70  16.71  16.70   253002.0   4226400.23\n",
       "2019-10-29 10:00:00  16.71  16.68  16.71  16.68   520025.0   8679970.83\n",
       "...                    ...    ...    ...    ...        ...          ...\n",
       "2019-10-29 14:31:00  16.82  16.83  16.83  16.82   182220.0   3066045.40\n",
       "2019-10-29 14:32:00  16.83  16.83  16.84  16.82   489302.0   8236260.64\n",
       "2019-10-29 14:33:00  16.83  16.82  16.84  16.82   288600.0   4857584.00\n",
       "2019-10-29 14:34:00  16.82  16.83  16.84  16.82   252092.0   4242779.44\n",
       "2019-10-29 14:35:00  16.83  16.82  16.83  16.82   428300.0   7209004.00\n",
       "2019-10-29 14:36:00  16.82  16.85  16.85  16.82   819100.0  13788395.74\n",
       "2019-10-29 14:37:00  16.84  16.84  16.85  16.83   255923.0   4310376.09\n",
       "2019-10-29 14:38:00  16.83  16.82  16.84  16.81   567200.0   9544310.62\n",
       "2019-10-29 14:39:00  16.83  16.82  16.84  16.81   717560.0  12070802.43\n",
       "2019-10-29 14:40:00  16.82  16.81  16.82  16.80   235607.0   3960619.90\n",
       "2019-10-29 14:41:00  16.80  16.80  16.82  16.80   340540.0   5723429.00\n",
       "2019-10-29 14:42:00  16.80  16.81  16.81  16.79   486056.0   8166909.19\n",
       "2019-10-29 14:43:00  16.80  16.82  16.82  16.80   474361.0   7976260.32\n",
       "2019-10-29 14:44:00  16.82  16.82  16.82  16.81   261949.0   4405748.67\n",
       "2019-10-29 14:45:00  16.81  16.81  16.83  16.81   310400.0   5220694.40\n",
       "2019-10-29 14:46:00  16.82  16.83  16.83  16.82   459929.0   7738115.78\n",
       "2019-10-29 14:47:00  16.83  16.83  16.83  16.82   359122.0   6043664.04\n",
       "2019-10-29 14:48:00  16.82  16.83  16.83  16.82   367926.0   6190146.32\n",
       "2019-10-29 14:49:00  16.82  16.82  16.83  16.82   320957.0   5400481.74\n",
       "2019-10-29 14:50:00  16.82  16.82  16.83  16.82   385542.0   6487444.44\n",
       "2019-10-29 14:51:00  16.82  16.82  16.83  16.82   463000.0   7789842.24\n",
       "2019-10-29 14:52:00  16.82  16.87  16.87  16.82  2959534.0  49858901.68\n",
       "2019-10-29 14:53:00  16.87  16.90  16.91  16.87  2022700.0  34174144.55\n",
       "2019-10-29 14:54:00  16.89  16.90  16.90  16.88   927300.0  15667605.96\n",
       "2019-10-29 14:55:00  16.89  16.89  16.90  16.88   802510.0  13556824.30\n",
       "2019-10-29 14:56:00  16.88  16.87  16.89  16.87   821190.0  13862545.20\n",
       "2019-10-29 14:57:00  16.87  16.89  16.90  16.86   542624.0   9159236.64\n",
       "2019-10-29 14:58:00  16.89  16.89  16.89  16.89     5900.0     99651.00\n",
       "2019-10-29 14:59:00  16.89  16.89  16.89  16.89        0.0         0.00\n",
       "2019-10-29 15:00:00  16.89  16.91  16.91  16.89  1513462.0  25592642.42\n",
       "\n",
       "[240 rows x 6 columns]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.columns=data.columns.map(lambda x: x+'_'+security)\n",
    "data['datetime']=data.index\n",
    "data.index=[x for x in range(len(data))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for x in range(1,len(pre_stock.head(20))):\n",
    "    code=pre_stock.loc[x]['code']\n",
    "    display_name=pre_stock.loc[x]['display_name']\n",
    "    temp = jqdatasdk.get_price(security, start_date=start_date, end_date=end_date,\n",
    "                                           frequency='daily',\n",
    "                                           fields=None,\n",
    "                                           skip_paused=False, fq='pre')\n",
    "    temp.columns=temp.columns.map(lambda x: x+'_'+code)\n",
    "    temp['datetime']=temp.index\n",
    "    temp.index=[x for x in range(len(temp))]\n",
    "    data=pd.merge(data,temp,on='datetime')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv('../data/Test.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取集合竞价数据 call_auction\n",
    "call_auction = jqdatasdk.get_call_auction(security, start_date, end_date, fields=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "call_auction.drop(['time'],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
